package leetcode;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-12-12 00:39
 **/
public class LeetCode5937 {

    class Location{
        String name;
        int score;
        Location(String _name, int _score){
            name = _name;
            score = _score;
        }
    }

    List<Location> list;
    int ind;
    public LeetCode5937() {
        list = new ArrayList<>();
        ind = 0;
    }

    public void add(String name, int score) {
        Location cloc = new Location(name, score);
        int n = list.size();
        if(n == 0 || list.get(0).score < score){
            list.add(0, cloc);
        } else if(list.get(n - 1).score > score){
            list.add(cloc);
        } else{
            int l = 0, r = n;
            while(l < r){
                int m = l + (r - l) / 2;
                if(list.get(m).score <= score) r = m;
                else l = m + 1;
            }
            int l1 = l;
            l = 0;
            r = n;
            while(l < r){
                int m = l + (r - l) / 2;
                if(list.get(m).score < score) r = m;
                else l = m + 1;
            }
            int l2 = l;
            l = l1;
            r = l2;
            while(l < r){
                int m = l + (r - l) / 2;
                if(list.get(m).name.compareTo(name) > 0) r = m;
                else l = m + 1;
            }
            list.add(l, cloc);
        }

    }

    public String get() {
        int c = ind;
        ind++;
        return(list.get(c).name);
    }

/**
 * Your SORTracker object will be instantiated and called as such:
 * SORTracker obj = new SORTracker();
 * obj.add(name,score);
 * String param_2 = obj.get();
 */


}
